<?php
require '../../include/library.inc.php';
require '../../include/admin_login.inc.php';
require '../../include/paging.inc.php';

$category_id = intval($_GET['cat']);
$lang = 1;
$sql = "SELECT
			c.category_id,
			c.image,
			c.order_number,
			c.published,
			
			d.Name
			
			
		FROM
			category AS c,
			category_description AS d
		WHERE
		
			c.category_id = d.category_id
			
			AND
			
			d.lang_id = '".$lang."'
		  ";
		  


if (!isset($_GET['sort'])) $_GET['sort'] = 1;
if (!isset($_GET['sortBy'])) $_GET['sortBy'] = 3;

$paging = new Paging($sql, $_GET['sortBy'], $_GET['sort'], array(3=>"Подредба"), 30);
$result = $paging->query();
	
	head_admin("Категории");
?>
<?php if ($_SESSION['message']) { ?>

<div class="message green">
  <?=$_SESSION['message']?>
</div>
<?php unset($_SESSION['message']); } ?>
<div class="topbuttons"> <a href="category_new.php">Добави ноа категория</a> </div>
<h3>Категории (
  <?=$paging->count()?>
  )</h3>
<table id="listing" width="100%" cellpadding="0" cellspacing="0">
  <thead>
    <tr>
      <td>Снимка</td>
      <td>Име</td>
      <td>Публикуван</td>
      <td>Подредба</td>
      <td>Действия</td>
    </tr>
  </thead>
  <tbody>
    <?php
			  
			  
			  $i=1;
			  while ($row = mysql_fetch_object($result)) {				  
			?>
    <tr class="<?=(($i%2)?"none":"zebra")?>">
      <td style="width:200px;"><a href="category_edit.php?category_id=<?=$row->category_id?>"  rel="logos"><img class="thumb" src="../catalogimage/categoryimage/<?=$row->image?>" height="100"/></a></td>
      <td><a href="category_edit.php?category_id=<?=$row->category_id?>" title="Редактирай">
        <?=sth($row->Name)?>
        </a></td>
      <td class="switch"><?php if ($row->published) { ?>
        <a href="category_publish.php?category_id=<?=$row->category_id?>&publish=0" class="turn_on" name="turn_on" title="Спри"></a>
        <?php } else { ?>
        <a href="category_publish.php?category_id=<?=$row->category_id?>&publish=1" class="turn_off" name="turn_off" title="Публикувай"></a>
        <?php } ?></td>
      <td class="sort"><?php if ($i != 1) { ?>
        <a name="Up" class="sorting_up" title="Нагоре" href="category_direction.php?category_id=<?=$row->category_id?>&direction=1"></a>
        <?php } ?>
        <?php if ($i != ($paging->count())) { ?>
        <a name="Down" class="sorting_down" title="Надолу" href="category_direction.php?category_id=<?=$row->category_id?>&direction=-1"></a>
        <?php } ?>
        &nbsp;<!--ie6 bug--></td>
      <td class="icons"><a name="Top" class="sorting_top" title="Top" href="category_direction.php?category_id=<?=$row->category_id?>&top=1">Top</a> <a href="category_edit.php?category_id=<?=$row->category_id?>" class="edit" title="Редактирай">Редактирай</a> <a onClick="if (window.confirm('Сигурен ли си, че искаш да изтриеш <?=sth($row->Name)?>?')) { document.location='category_del.php?category_id=<?=$row->category_id?>'; return false; }" class="delete" title="Изтрий">Изтрий</a></td>
    </tr>
    <?php
              $i++;    
            } 
         ?>
  </tbody>
</table>
<div class="pagingwrap">
  <div class="paging">
    <?=$paging->display()?>
  </div>
</div>
<?php
	foot_admin(); 
?>
